﻿using System.ComponentModel;
using Medicalsystem.MCP.FormDesigner.Common;
using Medicalsystem.MCP.FormDesigner.Define;
using Medicalsystem.MCP.FormDesigner.Interface;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// 多行文本输入框
    /// </summary>
    [ToolboxItem(false)]
    public class MultiTextBox : System.Windows.Forms.TextBox, ICtrlUI
    {
        public MultiTextBox() { }
        public MultiTextBox(Model model) : this(model, EDesignModeState.Run) { }

        public MultiTextBox(Model model, EDesignModeState designModeState)
        {
            this.Multiline = true;
            this._model = model;
            this._designModeState = designModeState;

            if (_designModeState == EDesignModeState.Design)
            {
                this.TabStop = false;
                this.ReadOnly = true;
                this.BackColor = System.Drawing.Color.White;
            }
        }

        private EDesignModeState _designModeState = EDesignModeState.Run;
        private Model _model;

        protected GetCtrlProperty _propertyObject = null;
        protected bool _visibleZ = true;

        private bool _readOnlyZ = false;

        #region ICtrlUI 成员

        public bool VisibleZ
        {
            get
            {
                return _visibleZ;
            }
            set
            {
                _visibleZ = value;
            }
        }

        public virtual EBorderStyle BorderStyleZ
        {
            get
            {
                return BorderStyleConvert.ToEBorderStyle(this.BorderStyle);
            }
            set
            {
                this.BorderStyle = BorderStyleConvert.ToBorderStyle(value);
            }
        }

        public string ShowText
        {
            get
            {
                return this.Text;
            }
            set
            {
                this.Text = value;
            }
        }

        #endregion ICtrlUI 成员

        #region ICtrlBase 成员

        public string CtrlID
        {
            get
            {
                return this.Name;
            }
            set
            {
                this.Name = value;
            }
        }

        public EDesignModeState DesignModeState
        {
            get
            {
                return _designModeState;
            }
            set
            {
                _designModeState = value;
            }
        }

        public virtual GetCtrlProperty PropertyObject
        {
            get
            {
                if (this._propertyObject == null)
                {
                    this._propertyObject = new GetMultiTextBoxProperty(this);
                }

                return this._propertyObject;
            }
        }

        public virtual EUISizeMode UISizeMode
        {
            get { return EUISizeMode.AllowBoth; }
        }

        public Model Model
        {
            get
            {
                return _model;
            }
        }

        #endregion ICtrlBase 成员

        #region 自定义属性

        /// <summary>
        /// 是否只读-该值在设计时只保存其值-不赋值到实际应用
        /// </summary>
        public bool ReadOnlyZ
        {
            get { return _readOnlyZ; }
            set
            {
                _readOnlyZ = value;

                if (this.DesignModeState != EDesignModeState.Design)
                {
                    this.ReadOnly = value;
                }
            }
        }

        #endregion 自定义属性

        #region IXMLConvertor 成员

        public virtual string ToXML()
        {
            MultiTextBoxPropertyXML XML = new MultiTextBoxPropertyXML(this);
            return XML.ToXML();
        }

        public void FromXML(string strXML)
        {
            if (strXML.Length > 0)
            {
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(string.Format("<MultiTextBox>{0}</MultiTextBox>", strXML));

                FromXML(doc.DocumentElement.ChildNodes);
            }
        }

        public virtual void FromXML(System.Xml.XmlNodeList xns)
        {
            if (xns != null && xns.Count > 0)
            {
                MultiTextBoxPropertyXML XML = new MultiTextBoxPropertyXML(this);
                XML.FromXML(xns);
            }
        }

        #endregion IXMLConvertor 成员
        #region ICtrlBase 成员


        public System.Drawing.Image IcoForToolBox
        {
            get { return Properties.Resources.PropertiesHS; }
        }

        #endregion
    }
}